from sqlmodel import SQLModel,create_engine,Session
from sqlmodel.ext.asyncio.session import AsyncSession
from sqlalchemy.ext.asyncio import create_async_engine,async_sessionmaker
from sqlalchemy.orm import sessionmaker

from fastapi import Depends
from collections.abc import AsyncGenerator

DATABASE_URL = "postgresql://hg101:124578963hzm@localhost:5432/hg_quant"
engine = create_engine(DATABASE_URL,echo=True)

ASYNC_DATABASE_URL="postgresql+asyncpg://hg101:124578963hzm@localhost:5432/hg_quant"
async_engine=create_async_engine(ASYNC_DATABASE_URL,echo=True)

async_session=async_sessionmaker(
    bind=async_engine,
    class_=AsyncSession,
    expire_on_commit=False
)

async def get_session() -> AsyncGenerator[AsyncSession,None]:
    async with async_session() as session:
        yield session